package stu1;

import java.util.Scanner;

public class StuTest {
    Student[] stus=new Student[20];

    Scanner input=new Scanner(System.in);

    public void printInfo(){
        System.out.println("--学生管理系统---");
        System.out.println("1添加学生");
        System.out.println("2删除学生");
        System.out.println("3查询学生");
        System.out.println("0退出");
        System.out.println("请选择");
    }

    public static void main(String[] args) {
        StuTest st=new StuTest();
        st.start();
    }

    private void start() {

        int choose;
        do{
            printInfo();
           choose=input.nextInt();
           switch (choose){
               case 1:
                   addStu();
                   break;
               case 2:
                   delStu();
                   break;
               case 3:
                   queryStu();
                   break;
               case 0:
                   System.out.println("谢谢使用");
                   break;

           }
        }while (choose!=0);



    }

    private void queryStu() {
        System.out.println("编号\t姓名\t性别\t年龄");
        for (Student stu:stus){
            if(stu!=null){
                stu.print();
            }
        }


    }

    private void delStu() {
        System.out.println("---删除学生---");
        System.out.println("请输入学生编号");
        int num=input.nextInt();
        for (int i = 0; i < stus.length; i++) {
            if (stus[i]!=null&&stus[i].sNo==num){
                stus[i]=null;
                break;
            }
        }
    }

    private void addStu() {
        System.out.println("---添加学生---");
        System.out.println("请输入学号");
        int num=input.nextInt();
        System.out.println("请输入学生姓名");
        String name=input.next();
        System.out.println("请输入性别");
        String gender=input.next();
        System.out.println("请输入年龄");
        int age=input.nextInt();
        Student stu=new Student(num,name,gender,age);
        for (int i = 0; i < stus.length; i++) {

            if(stus[i]==null){
                stus[i]=stu;
                System.out.println("存入学生信息成功");
                return;
            }
        }


    }
}
